package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class AddElementToEndOfArray {
	public static void main(String[] argv) {
		String[] attributes = new String[]{"1", "abc", "level", null,
				"tah1986.com", "asdf 123"};
		String element = "www.tah1986.com";
		System.out.println(java.util.Arrays
				.toString(addElementToEndOfArray(attributes, element)));
	}

	public static String[] addElementToEndOfArray(String[] attributes, String element) {
		String[] attributesPlus = new String[attributes.length + 1];
		System.arraycopy(attributes, 0, attributesPlus, 0,
				attributes.length);
		attributesPlus[attributes.length] = element;
		attributes = attributesPlus;
		return attributes;
	}

	public static Object[] addElementToEndOfArray(Object[] attributes,
	                                              Object element) {
		Object[] attributesPlus = new Object[attributes.length + 1];
		System.arraycopy(attributes, 0, attributesPlus, 0,
				attributes.length);
		attributesPlus[attributes.length] = element;
		attributes = attributesPlus;
		return attributes;
	}
}
